package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.*;

import cn.wolfcode.luowowo.service.*;

import cn.wolfcode.luowowo.util.JsonResult;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.swing.*;
import java.util.List;

@RestController
@RequestMapping("/destinations")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;

    @Autowired
    private IRegionService regionService;

    @Autowired
    private IStrategyCatalogService strategyCatalogService;


    @Autowired
    private IStrategyService strategyService;


    @Autowired
    private ITravelService travelService;

    /**
     * 热门区域查询
     * @return
     */
    @GetMapping("/hotRegion")
    public Object hotRegion(){
        List<Region> list =  regionService.queryHotRegion();
        return JsonResult.success(list);
    }

    /**
     * 查每个区域下面的目的地(城市和县市)
     * @param regionId
     * @return
     */
    @GetMapping("/search")
    public Object search (String regionId){
        List<Destination> list = destinationService.queryByRegionId(regionId);
        return JsonResult.success(list);
    }


    /**
     * 导航吐司
     * @param destId
     * @return
     */
    @GetMapping("/toasts")
    public Object toasts(String destId){
        // 根据目的地Id  利用getToasts方法 查找到所有上级目的地
        List<Destination> toasts = destinationService.gettoasts(destId);
        return JsonResult.success(toasts);
    }


    /**
     * 根据目的地Id找寻分类概况/明细
     * @param destId
     * @return
     */
    @GetMapping("/catalogs")
    public Object catalogs(String destId){

        List<StrategyCatalog> catalogs =   strategyCatalogService.queryCatalogsByDestId(destId);
        return JsonResult.success(catalogs);

    }


    /**
     * 目的地下点击量前3的攻略
     * @param destId
     * @return
     */
    @GetMapping("/strategies/viewnumTop3")
    public Object ViewNumTop3(String destId){

        List<Strategy>  list = strategyService.queryViewNumTop3(destId);


        return JsonResult.success(list);
    }



    @GetMapping("/detail")
    public Object detail(String id){
        Destination destination = destinationService.get(id);
        return JsonResult.success(destination);
    }



    /**
     * 通过目的地Id 去找到当前目的地排名前三的游记
     * @param destId
     * @return
     */
    @GetMapping("/travels/viewnumTop3")
    public Object viewnumTop3(String destId){
        List<Travel> travels = travelService.queryViewNumTop3(destId);
        return JsonResult.success(travels);
    }

}
